package com.example.dishfo.myapplication.testtmp;

import android.util.Log;

import com.example.dishfo.myapplication.entity.User;
import com.example.dishfo.myapplication.network.netintr.UserService;
import com.example.dishfo.myapplication.network.resbean.HttpBean;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

import java.io.IOException;

import io.reactivex.Observable;
import io.reactivex.Observer;
import okhttp3.Request;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Subscriber;

/**
 *
 * 用于测试的Retrofit接口实现类
 */
public class TestUserService implements UserService {

    @Override
    public Observable<HttpBean> login(String useranme, String pwd) {
        Observable<HttpBean> observable=Observable.create(e -> {
            try{

                Gson gson=new Gson();
                HttpBean bean=new HttpBean();
                bean.setCode(1);
                bean.setMsg("login succeed");
                User user=new User();
                user.setId("1");
                user.setUserName(useranme);

                JsonObject var1=new JsonObject();
                String res=gson.toJson(user);
                var1.addProperty("user",res);
                var1.addProperty("token","123456789");

                bean.setForm(new Gson().toJson(var1));

                Thread.sleep(3000);
                e.onNext(bean);
                e.onComplete();
            }catch (Exception ex){
                e.onError(ex);
            }

        });
        return observable;
    }

    @Override
    public Observable<HttpBean> forgetPwd(String name) {
        return null;
    }
    @Override
    public Observable<HttpBean> toSignUp(String email,String  user,String pwd)
    {
        Observable<HttpBean> observable=Observable.create(e -> {
            try{
                Log.d("test",Thread.currentThread().getName());
                Gson gson=new Gson();
                HttpBean bean=new HttpBean();
                bean.setCode(1);
                bean.setMsg("signup succeed");

                JsonObject object=new JsonObject();
                object.addProperty("result","请于邮箱中激活帐号");
                bean.setForm(new Gson().toJson(object));

                Thread.sleep(3000);
                e.onNext(bean);
                e.onComplete();
            }catch (Exception ex){
                e.onError(ex);
            }

        });
        return observable;
    }

    @Override
    public Observable<HttpBean> signUp(String name, String pwd) {
        return null;
    }

}
